//创建文章列表
function create_liebiao(json){
	var tbody=document.getElementById("liebiao_tbody");
	for(var i=0,len=json.length;i<len;i++){
		tbody.insertRow(i);
		tbody.rows[i].className=json[i].id;
		for(var j=0;j<5;j++){
			tbody.rows[i].insertCell(j);
			var elem=tbody.rows[i].cells[j];
			var id=json[i].id;
			switch(j){
				case 0:{
					elem.innerHTML=json[i].title;
					break;
				}
				case 1:{
					var date_id=parseInt(id);
					var date=new Date(date_id);
					elem.innerHTML=date.toLocaleString();
					break;
				}
				case 2:{
					var a=document.createElement("a");
					a.href="javascript:static_scan("+json[i].id+")";
					a.innerHTML="静态查看";
					elem.appendChild(a);
					break;
				}
				case 3:{
					var a=document.createElement("a");
					a.href="javascript:dyna_scan("+json[i].id+")";
					a.innerHTML="动态查看";
					elem.appendChild(a);
					break;
				}
				case 4:{
					var a=document.createElement("a");
					a.href="javascript:del_sub("+json[i].id+")";
					a.innerHTML="删除";
					elem.appendChild(a);
					break;
				}
			}
		}
	}
}
function liebiao_init(){
	get_ajax("../back_stage/user_center.php?liebiao_init=true",{},function(text){
		var json=JSON.parse(text);
		create_liebiao(json);
	},false);
}

//静态查看
function static_scan(id){
	var user=document.getElementById("user_id");
	var current_user=user.innerHTML;
	window.open("../love.php/user_"+current_user+"id_"+id+"type_display.html","_blank");
}
//动态查看
function dyna_scan(id){
	var user=document.getElementById("user_id");
	var current_user=user.innerHTML;
	window.open("../love.php/user_"+current_user+"id_"+id+"type_write.html","_blank");
}
//删除
function del_sub(id){
	get_ajax("../back_stage/user_center.php?del_sub=true",{id:id},function(text){
		if(text=="ok"){
			location.reload();
		}else{
			alert("系统错误"+text);
		}
	},false);
}
//新建
function new_sub(){
	window.open("edit.php","_blank");
}
//修改密码
function change_psd(){
	var go=true;
	document.getElementById("liebiao").style.display="none";
	document.getElementById("xiugai_password").style.display="block";
	var form=document.forms["psd"];
	//将出师值质空
	form.elements["old_psd"].value="";
	var tishi=document.getElementById("form_tishi");
	//注册事件
	//选中还原
	var o_new_psd=form.elements["new_psd"];
	o_new_psd.onfocus=function(){
		go=true;
		tishi.innerHTML="";
	}
	o_new_psd_again=form.elements["new_psd_again"];
	o_new_psd_again.onfocus=function(){
			go=true;
			tishi.innerHTML="";
	}
	//离开检查
	o_new_psd_again.onblur=function(){
		var new_psd=o_new_psd.value;
		var new_psd_again=o_new_psd_again.value;
		if(new_psd_again!=new_psd){
			tishi.innerHTML="两次密码输入不一致";
			go=false;
		}
	}
	form.onsubmit=function(event){
		preventDefault(event);
		var old=form.elements["old_psd"].value;
		var new_psd=form.elements["new_psd"].value;
		var new_psd_again=form.elements["new_psd_again"].value;
		if(go){
			get_ajax("../back_stage/user_center.php",{change_psd:true,old:old,new_psd:new_psd,new_psd_again:new_psd_again},function(text){
				if(text=="ok"){
					tishi.innerHTML="修改成功";
					setTimeout(function(){
						document.getElementById("liebiao").style.display="block";
						document.getElementById("xiugai_password").style.display="none";
					},1000);
				}else{
					tishi.innerHTML=text;
				}
			},false);
		}
	}
}
window.onload=function(){
	liebiao_init();
}
